stage.set_axis(100)
stage.create_grid_overlay(10, "grey")
stage.set_background("soccerfield")
ballx = -80
bally = random.randint(-100,100)
# sprite = codesters.Sprite("image", x, y)
ball = codesters.Sprite("soccerball", ballx, bally)
netx = 90
nety = random.randint(-100,100)
# sprite = codesters.Sprite("image", x, y)
net = codesters.Sprite("soccernet", netx, nety)
net.flip_right_left()
#sprite = codesters.Line(x-start, y-start, x-end, y-end, "color")
line = codesters.Line(ballx, bally, netx, nety, "blue")
slopeguess = float(line.ask("What is the slope of this line?"))
rise = nety - bally
run = netx - ballx
slope = rise / run
t = codesters.Teacher()
params = t.get_parameters_for_function("Text")
try:
tval1 = params[0][0]
except:
tval1 = "DNE"
try:
tval2 = params[0][1]
except:
tval2 = "DNE"
try:
tval3 = params[0][2]
except:
tval3 = "DNE"
t1 = TestObjective()
t1.add_success(tval1 == "slope", "Great job!")
t1.add_failure(tval1 == "DNE", "Did you add a Sprite at Position command?")
t1.add_failure(tval1 == '"slope"', "Did you put slope in quotes? Delete the quotes marks!")
t2 = TestObjective()
t2.add_success(tval2 == "0", "Great job!")
t2.add_failure(tval2 == "DNE", "Did you delete the x-coordinate?")
t2.add_failure(tval2 == "100", "Don't forget to change the x-coordinate to 0!")
t3 = TestObjective()
t3.add_success(tval3 == "30", "Great job!")
t3.add_failure(tval3 == "DNE", "Did you delete the y-coordinate?")
t3.add_failure(tval3 == "200", "Don't forget to change the y-coordinate to 30!")
tester = TestManager()
tester.add_test_list([t1, t2, t3])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)